package thread;

public class SyncDemo3 {
    public static void main(String[] args) {
        Foo f = new Foo();
        Thread t1 = new Thread(){
            public void run() {
                Foo.dosome();
            }
        };

        Thread t2 = new Thread(){
            public void run() {
                Foo.dosome();
            }
        };
        t1.start();
        t2.start();

    }
}

class Foo{
    public  static void dosome(){
        synchronized (Foo.class){
            Thread t = Thread.currentThread();
            System.out.println(t.getName()+"调用方法");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("执行完毕");
        }

    }
}
